<script type="text/javascript">     
$(document).ready(function(){

    // check for first change in form
    <? if($this->input->post("submit_action")!==FALSE){ ?>
        var hasChanged = true;                 
    <? } else { ?>
        var hasChanged = false;                
        $("input:submit").addClass("disabled");
    <? } ?>
    $("input,textarea").live("change", function(){
        if(hasChanged == false){
            hasChanged = true;
            $("input:submit").removeClass("disabled");
        }
    });

    //cancel button
    $(".cancel").click(function(){
        if (hasChanged != false)
            if (!confirm("If you leave this page now, you will loose the changes you've just made.\n\nProceed anyway?\n")) return false;
            window.location.href='<?=site_url("admin/applications")?>';
        return false;
    });

    var image = $(".ImageManager_Widget img");
    var image_input = $(".ImageManager_Widget input.img_path");

    function ImageManagerCallback(img_path){

        display_path = "<?=base_url().UPLOADS_FOLDER.PRODUCT_IMG_FOLDER.THUMBS_FOLDER;?>"+img_path;
        $(image).attr("src", display_path).fadeIn();
        $(image_input).val(img_path).change();                 

    }

    // bind triggers that open the ImageManager
    $(".open_image_manager").live("click", function () {       
        mcImageManager.open('','','',
            function(img_path){
                ImageManagerCallback(img_path);
            },
            { 
				rootpath : '{0}/<?=PRODUCT_IMG_FOLDER?>',
				document_base_url : '<?=base_url().UPLOADS_FOLDER.PRODUCT_IMG_FOLDER?>',
				relative_urls : true
			}
        );
        return false;
    }); 
         
                  
});  
       
</script>

<div id="content">  

<? if($this->input->post("submit_action") !== FALSE){ ?>
    <div class="response"><?=validation_errors()?></div>                
<? } ?>

<? if(is_array($response)){?>
    <div class="response">
        <span class="<?=$response["class"]?>"><?=$response["msg"]?></span>
    </div>
<?}?>
     

    <form action="" method="post">

    <div class="float_block_right">
        <a href="#" class="button cancel">CANCEL</a>
        <input type="submit" class="button " value="SAVE CHANGES">  
    </div>


    <? if ($action=='update') { ?>
        <h1>Edit product Application <i><?=$item['Name_Applications']?></i></h1>
    <? } else { ?>
        <h1>Add new product Application</h1>
    <? } ?>

    <? if(!is_array($response)){?>

    <div class="content_block">
        <h4>Name</h4>
        <input type="text" name="name" maxlength="80" value="<?=set_value('name', $item['Name_Applications'])?>" />
    </div>

    <div id="image" class="content_block">
        <h4>Image</h4>
        <div class="ImageManager_Widget">
            <img src="<?=Thumbnail(base_url().UPLOADS_FOLDER.PRODUCT_IMG_FOLDER.set_value('image', $item['Image_Applications']))?>" style="display:block" />
            <a class="open_image_manager button" href="#">SELECT IMAGE</a>
            <input type="hidden" name="image" class="img_path" value="<?=set_value('image', $item['Image_Applications'])?>" />    
        </div>
    </div>  
    <? }?> 

    <input type="hidden" name="id" value="<?=$item['id_Applications']?>" /> 
    <input type="hidden" name="token" value="<?=$token?>" /> 
    <input type="hidden" name="submit_action" value="<?=$action?>" />

    </form>

</div>